#include <math.h>
#include "ExpFunctionNode.h"
#include "..\Common\AssertHelper.h"

using namespace std;

namespace CExpression
{
	void ExpFunctionNode::Eval(ExecuteContext &context)
	{
		(this->parameters)[0]->Eval(context);
		if(AssertHelper::ExpectType(context.TempResultType(),ExecuteRunTimeType::Double,context,TEXT("Exp function parameter must be double type.")))
		{
			context.SetGlobalTempNum(exp(context.GlobalTempNum()));
			context.SetTempResultType(ExecuteRunTimeType::Double);
		}
	}

	shared_ptr<Node> ExpFunctionNode::Clone(Expression &parent)
	{
		shared_ptr<Node> result(new ExpFunctionNode());
		static_cast<FunctionNode*>(result.get())->AddParameter((this->parameters)[0]->Clone(parent));
		return result;
	}
}